/**
 * @对于输入的数字打印出条形图
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <cs50.h>

#define WIDTH 80
#define COUNT 8

int main (int argc, char *argv[]) {
	int array[COUNT];
	float s = 0;

	// 获取输入的数字并求和
	for (int i=0; i<COUNT; i++ ) {
		
		do {
			printf("请输入第%d类个数：", i+1);
			array[i] = GetInt();
		} while (array[i]<0);

		s += array[i];
	}

	// 规范化并打印条形图
	for (int i=0; i<COUNT; i++) {
		array[i] = (int)(array[i] / s * WIDTH);

		printf("第%d类\n", i+1);
		for (int j=0; j<array[i]; j++) {
			printf("#");
		}
		printf("\n");
	}
}
													
